package StringTest;

import java.util.Scanner;

public class Test2 {
    /*
    给定一个字符串S,去掉标点符号和空格,将所有大写字母都转换成小写字母,如果他是回文串,返回true,如果不是,返回false
    字母和数字都属于字母数字字符
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入字符串:");
        String s = sc.nextLine();
        boolean b = chack(s);
        if (b){
            System.out.println("该字符串是回文串");
        }else{
            System.out.println("该字符串不是回文串");
        }
    }
    public static boolean chack(String str){
        char[] str2 = str.toCharArray();
        StringBuilder str3 = new StringBuilder();
        //转换成全部小写
        for (int i = 0; i <str2.length ; i++) {
            if(str2[i]>=65||str2[i]<90){
                str2[i] +=32;
            }
        }
        //去掉标点符号和空格
        for (int i = 0; i < str2.length; i++) {
            if(str2[i]>=97||str2[i]<=122){
                str3.append(str2[i]);
            }
        }
        String str4 = str3.toString();
        char[] str5 = str4.toCharArray();
        int flag=0;
        for (int i = 0; i < str5.length ; i++) {
            if(str5[i]==str5[str5.length-i-1]){
                flag++;
            }
        }
        if(flag==str5.length){
            return true;
        }else{
            return false;
        }
    }

}
